package edu.ccut.saturn.manager.bundles.core;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IDataItem;
import edu.ccut.saturn.component.IParameterContext;

public class DataItemListToMapList extends DefaultComponent {

	@SuppressWarnings("unchecked")
	@Override
	public void execute(IParameterContext parameterContext) throws Exception {
		List<IDataItem> list = (List<IDataItem>)parameterContext.getParameterValue(0);
		List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
		if(list != null){
			for(IDataItem dataItem: list){
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("name", dataItem.getName());
				map.put("column", dataItem.getColumn());
				map.put("columnAlias", dataItem.getColumnAlias());
				map.put("javaType", dataItem.getJavaType());
				result.add(map);
			}
		}
		parameterContext.setParameter(1, result);
	}
}
